<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
   
   <meta name="description" content="command line parsing">
    
    <meta name="author" content="John S. Urban" >
    <link rel="icon" href="../favicon.png">

    <title>get_subcommand &ndash; M_CLI2</title>

    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/pygments.css" rel="stylesheet">
    <link href="../css/font-awesome.min.css" rel="stylesheet">
    <link href="../css/local.css" rel="stylesheet">
    
    <link  href="../tipuesearch/tipuesearch.css" rel="stylesheet">
    
    

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    
    <script src="../js/jquery-2.1.3.min.js"></script>
    <script src="../js/svg-pan-zoom.min.js"></script>

  </head>

  <body>

    <!-- Fixed navbar -->
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="../index.html">M_CLI2 </a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
        
            <li class="dropdown hidden-xs visible-sm visible-md hidden-lg">
              <a href="#" class="dropdown-toggle"
              data-toggle="dropdown" role="button"
              aria-haspopup="true"
     aria-expanded="false">Contents <span class="caret"></span></a>
        <ul class="dropdown-menu">
          
              
            <li><a href="../lists/files.html">Source Files</a></li>
        
        
        
            <li><a href="../lists/modules.html">Modules</a></li>
        
            
                                
            <li><a href="../lists/procedures.html">Procedures</a></li>
        
               
            <li><a href="../lists/types.html">Derived Types</a></li>
        
        
            <li><a href="../lists/programs.html">Programs</a></li>
        
            </ul>
            </li>


<li class="visible-xs hidden-sm visible-lg"><a href="../lists/files.html">Source Files</a></li>



<li class="visible-xs hidden-sm visible-lg"><a href="../lists/modules.html">Modules</a></li>



<li class="visible-xs hidden-sm visible-lg"><a href="../lists/procedures.html">Procedures</a></li>

                             
<li class="visible-xs hidden-sm visible-lg"><a href="../lists/types.html">Derived Types</a></li>


<li class="visible-xs hidden-sm visible-lg"><a href="../lists/programs.html">Programs</a></li>

          </ul>
        
        <form action="../search.html" class="navbar-form navbar-right" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search" name="q" id="tipue_search_input" autocomplete="off" required>
        </div>
<!--
        <button type="submit" class="btn btn-default">Submit</button>
-->
        </form>
        
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="container">
    
  
  <div class="row">
    <h1>get_subcommand
      <small>Function</small>
    
    </h1>
    
<div class="row">
  <div class="col-lg-12">
<div class="well well-sm">
  <ul class="list-inline" style="margin-bottom:0px;display:inline">
     
     
     
     
    
    
     <li><i class="fa fa-list-ol"></i>
       <a data-toggle="tooltip"
    data-placement="bottom" data-html="true"
    title="15.9% of total for procedures.">47 statements</a>
     </li> 
     
     
     
    <li><i class="fa fa-code"></i><a href="../src/M_CLI2.F90"> Source File</a></li>
     
     
  </ul>
  <ol class="breadcrumb in-well text-right">
  
    
     <li><a href='../sourcefile/m_cli2.f90.html'>M_CLI2.F90</a></li>
    
     <li><a href='../module/m_cli2.html'>M_CLI2</a></li>
    
  
     <li class="active">get_subcommand</li>
  </ol>
</div>
</div>
</div>
<script>
  $(function () {
  $('[data-toggle="tooltip"]').tooltip()
  })
</script>

  </div>
  
  <div class="row">
    <div class="col-md-3 hidden-xs hidden-sm visible-md visible-lg">
    
<div id="sidebar">
  
<h3>Contents</h3>
 



<div class="panel panel-primary">
  <div class="panel-heading text-left"><h3 class="panel-title"><a data-toggle="collapse" href="#vars-0">Variables</a></h3></div>
  <div id="vars-0" class="panel-collapse collapse">
    <div class="list-group">
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-array">array</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-cmdarg">cmdarg</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-i">i</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-ilongest">ilongest</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-j">j</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-prototype">prototype</a>
      
    </div>
  </div>
</div>




















<div class="panel panel-primary">
  <div class="panel-heading text-left"><h3 class="panel-title">Source Code</h3></div>
  <div class="list-group">
    <a class="list-group-item" href="../proc/get_subcommand.html#src">get_subcommand</a>
  </div>
</div>



</div>

    </div>
    
    <div class="col-md-9" id='text'>
    <h2>
public function get_subcommand() result(sub)
    
    
   
</h2>
    
  


    
    <h2 id="name">NAME</h2>
<div class="codehilite"><pre><span></span><code><span class="nv">get_subcommand</span><span class="ss">(</span><span class="mi">3</span><span class="nv">f</span><span class="ss">)</span> <span class="o">-</span> [<span class="nv">ARGUMENTS</span>:<span class="nv">M_CLI2</span>] <span class="nv">special</span><span class="o">-</span><span class="nv">case</span> <span class="nv">routine</span> <span class="k">for</span>
<span class="nv">handling</span> <span class="nv">subcommands</span> <span class="nv">on</span> <span class="nv">a</span> <span class="nv">command</span> <span class="nv">line</span>
<span class="ss">(</span><span class="nv">LICENSE</span>:<span class="nv">PD</span><span class="ss">)</span>
</code></pre></div>

<h2 id="synopsis">SYNOPSIS</h2>
<div class="codehilite"><pre><span></span><code><span class="k">function</span><span class="w"> </span><span class="nf">get_subcommand</span><span class="p">()</span><span class="w"></span>

<span class="w"> </span><span class="n">character</span><span class="p">(</span><span class="n">len</span><span class="p">=:),</span><span class="n">allocatable</span><span class="w"> </span><span class="p">::</span><span class="w"> </span><span class="n">get_subcommand</span><span class="w"></span>
</code></pre></div>

<h2 id="description">DESCRIPTION</h2>
<div class="codehilite"><pre><span></span><code>In the special case when creating a program with subcommands it
is assumed the first word on the command line is the subcommand. A
routine is required to handle response file processing, therefore
this routine (optionally processing response files) returns that
first word as the subcommand name.

It should not be used by programs not building a more elaborate
command with subcommands.
</code></pre></div>

<h2 id="returns">RETURNS</h2>
<div class="codehilite"><pre><span></span><code>NAME   name of subcommand
</code></pre></div>

<h2 id="example">EXAMPLE</h2>
<p>Sample program:</p>
<div class="codehilite"><pre><span></span><code><span class="n">program</span><span class="w"> </span><span class="s">demo_get_subcommand</span><span class="w"></span>
<span class="sx">!x! SUBCOMMANDS</span><span class="w"></span>
<span class="sx">!x! For a command with subcommands like git(1)</span><span class="w"></span>
<span class="sx">!x! you can make separate namelists for each subcommand.</span><span class="w"></span>
<span class="sx">!x! You can call this program which has two subcommands (run, test),</span><span class="w"></span>
<span class="sx">!x! like this:</span><span class="w"></span>
<span class="sx">!x!    demo_get_subcommand --help</span><span class="w"></span>
<span class="sx">!x!    demo_get_subcommand run -x -y -z -title -l -L</span><span class="w"></span>
<span class="sx">!x!    demo_get_subcommand test -title -l -L -testname</span><span class="w"></span>
<span class="sx">!x!    demo_get_subcommand run --help</span><span class="w"></span>
<span class="w">   </span><span class="n">implicit</span><span class="w"> </span><span class="n">none</span><span class="w"></span>
<span class="sx">!x! DEFINE VALUES TO USE AS ARGUMENTS WITH INITIAL VALUES</span><span class="w"></span>
<span class="w">   </span><span class="nb">real</span><span class="w">               </span><span class="p">::</span><span class="w"> </span><span class="n">x</span><span class="p">=</span><span class="o">-</span><span class="mf">999.0</span><span class="p">,</span><span class="n">y</span><span class="p">=</span><span class="o">-</span><span class="mf">999.0</span><span class="p">,</span><span class="n">z</span><span class="p">=</span><span class="o">-</span><span class="mf">999.0</span><span class="w"></span>
<span class="w">   </span><span class="n">character</span><span class="p">(</span><span class="n">len</span><span class="p">=</span><span class="mi">80</span><span class="p">)</span><span class="w">  </span><span class="p">::</span><span class="w"> </span><span class="nb">title</span><span class="p">=</span><span class="s">&quot;not set&quot;</span><span class="w"></span>
<span class="w">   </span><span class="nb">logical</span><span class="w">            </span><span class="p">::</span><span class="w"> </span><span class="n">l</span><span class="p">=.</span><span class="n">false</span><span class="p">.</span><span class="w"></span>
<span class="w">   </span><span class="nb">logical</span><span class="w">            </span><span class="p">::</span><span class="w"> </span><span class="n">l_</span><span class="p">=.</span><span class="n">false</span><span class="p">.</span><span class="w"></span>
<span class="w">   </span><span class="n">character</span><span class="p">(</span><span class="n">len</span><span class="p">=</span><span class="mi">80</span><span class="p">)</span><span class="w">  </span><span class="p">::</span><span class="w"> </span><span class="n">testname</span><span class="p">=</span><span class="s">&quot;not set&quot;</span><span class="w"></span>
<span class="w">   </span><span class="n">character</span><span class="p">(</span><span class="n">len</span><span class="p">=</span><span class="mi">20</span><span class="p">)</span><span class="w">  </span><span class="p">::</span><span class="w"> </span><span class="n">name</span><span class="w"></span>
<span class="w">   </span><span class="n">call</span><span class="w"> </span><span class="n">parse</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="w"> </span>!<span class="n">x</span>!<span class="w"> </span><span class="n">DEFINE</span><span class="w"> </span><span class="n">AND</span><span class="w"> </span><span class="n">PARSE</span><span class="w"> </span><span class="n">COMMAND</span><span class="w"> </span><span class="n">LINE</span><span class="w"></span>
<span class="w">   </span>!<span class="n">x</span>!<span class="w"> </span><span class="n">ALL</span><span class="w"> </span><span class="n">DONE</span><span class="w"> </span><span class="n">CRACKING</span><span class="w"> </span><span class="n">THE</span><span class="w"> </span><span class="n">COMMAND</span><span class="w"> </span><span class="n">LINE</span><span class="p">.</span><span class="w"></span>
<span class="w">   </span>!<span class="n">x</span>!<span class="w"> </span><span class="n">USE</span><span class="w"> </span><span class="n">THE</span><span class="w"> </span><span class="n">VALUES</span><span class="w"> </span><span class="n">IN</span><span class="w"> </span><span class="n">YOUR</span><span class="w"> </span><span class="n">PROGRAM</span><span class="p">.</span><span class="w"></span>
<span class="w">   </span><span class="nb">write</span><span class="p">(</span><span class="o">*</span><span class="p">,</span><span class="o">*</span><span class="p">)</span><span class="o">&#39;</span><span class="n">command</span><span class="w"> </span><span class="n">was</span><span class="w"> </span><span class="s">&#39;,name</span>
<span class="s">   write(*,*)&#39;</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span><span class="w"> </span><span class="k">...</span><span class="c">. &#39;,x,y,z</span><span class="w"></span>
<span class="w">   </span><span class="nb">write</span><span class="p">(</span><span class="o">*</span><span class="p">,</span><span class="o">*</span><span class="p">)</span><span class="o">&#39;</span><span class="nb">title</span><span class="w"> </span><span class="k">...</span><span class="c">. &#39;,title</span><span class="w"></span>
<span class="w">   </span><span class="nb">write</span><span class="p">(</span><span class="o">*</span><span class="p">,</span><span class="o">*</span><span class="p">)</span><span class="o">&#39;</span><span class="n">l</span><span class="p">,</span><span class="n">l_</span><span class="w"> </span><span class="k">...</span><span class="c">.. &#39;,l,l_</span><span class="w"></span>
<span class="w">   </span><span class="nb">write</span><span class="p">(</span><span class="o">*</span><span class="p">,</span><span class="o">*</span><span class="p">)</span><span class="o">&#39;</span><span class="n">testname</span><span class="w"> </span><span class="p">.</span><span class="w"> </span><span class="s">&#39;,testname</span>
<span class="s">contains</span>
<span class="s">subroutine parse(name)</span>
<span class="s">!x! PUT EVERYTHING TO DO WITH COMMAND PARSING HERE FOR CLARITY</span>
<span class="s">use M_CLI2, only : set_args, get_args, get_args_fixed_length</span>
<span class="s">use M_CLI2, only : get_subcommand</span>
<span class="s">use M_CLI2, only : CLI_RESPONSE_FILE</span>
<span class="s">character(len=*)              :: name    ! the subcommand name</span>
<span class="s">character(len=:),allocatable  :: help_text(:), version_text(:)</span>
<span class="s">   CLI_RESPONSE_FILE=.true.</span>
<span class="s">! define version text</span>
<span class="s">   version_text=[character(len=80) :: &amp;</span>
<span class="s">      &#39;</span><span class="p">@(</span>#<span class="p">)</span><span class="n">PROGRAM</span><span class="p">:</span><span class="w">     </span><span class="n">demo_get_subcommand</span><span class="w">            </span><span class="o">&gt;</span><span class="s">&#39;, &amp;</span>
<span class="s">      &#39;</span><span class="p">@(</span>#<span class="p">)</span><span class="n">DESCRIPTION</span><span class="p">:</span><span class="w"> </span><span class="n">My</span><span class="w"> </span><span class="nb">demo</span><span class="w"> </span><span class="n">program</span><span class="w">  </span><span class="o">&gt;</span><span class="s">&#39;, &amp;</span>
<span class="s">      &#39;</span><span class="p">@(</span>#<span class="p">)</span><span class="n">VERSION</span><span class="p">:</span><span class="w">     </span><span class="mf">1.0</span><span class="w"> </span><span class="mi">20200715</span><span class="w">     </span><span class="o">&gt;</span><span class="s">&#39;, &amp;</span>
<span class="s">      &#39;</span><span class="p">@(</span>#<span class="p">)</span><span class="n">AUTHOR</span><span class="p">:</span><span class="w">      </span><span class="n">me</span><span class="p">,</span><span class="w"> </span><span class="n">myself</span><span class="p">,</span><span class="w"> </span><span class="n">and</span><span class="w"> </span><span class="n">I</span><span class="o">&gt;</span><span class="s">&#39;, &amp;</span>
<span class="s">      &#39;</span><span class="p">@(</span>#<span class="p">)</span><span class="n">LICENSE</span><span class="p">:</span><span class="w">     </span><span class="n">Public</span><span class="w"> </span><span class="n">Domain</span><span class="w">    </span><span class="o">&gt;</span><span class="s">&#39;, &amp;</span>
<span class="s">      &#39;&#39; ]</span>
<span class="s">    ! general help for &quot;demo_get_subcommand --help&quot;</span>
<span class="s">    help_text=[character(len=80) :: &amp;</span>
<span class="s">     &#39;</span><span class="w"> </span><span class="n">allowed</span><span class="w"> </span><span class="n">subcommands</span><span class="w"> </span><span class="n">are</span><span class="w">          </span><span class="s">&#39;, &amp;</span>
<span class="s">     &#39;</span><span class="w">   </span><span class="o">*</span><span class="w"> </span><span class="nb">run</span><span class="w">  </span><span class="o">-</span><span class="n">l</span><span class="w"> </span><span class="o">-</span><span class="n">L</span><span class="w"> </span><span class="o">-</span><span class="nb">title</span><span class="w"> </span><span class="o">-</span><span class="n">x</span><span class="w"> </span><span class="o">-</span><span class="n">y</span><span class="w"> </span><span class="o">-</span><span class="n">z</span><span class="w">   </span><span class="s">&#39;, &amp;</span>
<span class="s">     &#39;</span><span class="w">   </span><span class="o">*</span><span class="w"> </span><span class="n">test</span><span class="w"> </span><span class="o">-</span><span class="n">l</span><span class="w"> </span><span class="o">-</span><span class="n">L</span><span class="w"> </span><span class="o">-</span><span class="nb">title</span><span class="w">            </span><span class="s">&#39;, &amp;</span>
<span class="s">     &#39;&#39; ]</span>
<span class="s">   ! find the subcommand name by looking for first word on command</span>
<span class="s">   ! not starting with dash</span>
<span class="s">   name = get_subcommand()</span>
<span class="s">   select case(name)</span>
<span class="s">   case(&#39;</span><span class="nb">run</span><span class="o">&#39;</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">help_text</span><span class="p">=[</span><span class="n">character</span><span class="p">(</span><span class="n">len</span><span class="p">=</span><span class="mi">80</span><span class="p">)</span><span class="w"> </span><span class="p">::</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">     </span><span class="s">&#39;                                  &#39;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">     </span><span class="s">&#39; Help for subcommand &quot;run&quot;        &#39;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">     </span><span class="s">&#39;                                  &#39;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">     </span><span class="s">&#39;&#39;</span><span class="w"> </span><span class="p">]</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">set_args</span><span class="p">(</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;</span><span class="w"> </span><span class="s">&#39;-x 1 -y 2 -z 3 --title &quot;my title&quot; -l F -L F&#39;</span><span class="p">,</span><span class="o">&amp;</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;</span><span class="w"> </span><span class="n">help_text</span><span class="p">,</span><span class="n">version_text</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">,</span><span class="n">x</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args</span><span class="p">(</span><span class="s">&#39;y&#39;</span><span class="p">,</span><span class="n">y</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args</span><span class="p">(</span><span class="s">&#39;z&#39;</span><span class="p">,</span><span class="n">z</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args_fixed_length</span><span class="p">(</span><span class="s">&#39;title&#39;</span><span class="p">,</span><span class="nb">title</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args</span><span class="p">(</span><span class="s">&#39;l&#39;</span><span class="p">,</span><span class="n">l</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args</span><span class="p">(</span><span class="s">&#39;L&#39;</span><span class="p">,</span><span class="n">l_</span><span class="p">)</span><span class="w"></span>
<span class="w">   </span><span class="k">case</span><span class="p">(</span><span class="s">&#39;test&#39;</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">help_text</span><span class="p">=[</span><span class="n">character</span><span class="p">(</span><span class="n">len</span><span class="p">=</span><span class="mi">80</span><span class="p">)</span><span class="w"> </span><span class="p">::</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">     </span><span class="s">&#39;                                  &#39;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">     </span><span class="s">&#39; Help for subcommand &quot;test&quot;       &#39;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">     </span><span class="s">&#39;                                  &#39;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">     </span><span class="s">&#39;&#39;</span><span class="w"> </span><span class="p">]</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">set_args</span><span class="p">(</span><span class="o">&amp;</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;</span><span class="w"> </span><span class="s">&#39;--title &quot;my title&quot; -l F -L F --testname &quot;Test&quot;&#39;</span><span class="p">,</span><span class="o">&amp;</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;</span><span class="w"> </span><span class="n">help_text</span><span class="p">,</span><span class="n">version_text</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args_fixed_length</span><span class="p">(</span><span class="s">&#39;title&#39;</span><span class="p">,</span><span class="nb">title</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args</span><span class="p">(</span><span class="s">&#39;l&#39;</span><span class="p">,</span><span class="n">l</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args</span><span class="p">(</span><span class="s">&#39;L&#39;</span><span class="p">,</span><span class="n">l_</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">get_args_fixed_length</span><span class="p">(</span><span class="s">&#39;testname&#39;</span><span class="p">,</span><span class="n">testname</span><span class="p">)</span><span class="w"></span>
<span class="w">   </span><span class="k">case</span><span class="w"> </span><span class="n">default</span><span class="w"></span>
<span class="w">    </span>!<span class="w"> </span><span class="n">process</span><span class="w"> </span><span class="nb">help</span><span class="w"> </span><span class="n">and</span><span class="w"> </span><span class="nb">version</span><span class="w"></span>
<span class="w">    </span><span class="n">call</span><span class="w"> </span><span class="n">set_args</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">,</span><span class="n">help_text</span><span class="p">,</span><span class="n">version_text</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="nb">write</span><span class="p">(</span><span class="o">*</span><span class="p">,</span><span class="s">&#39;(*(a))&#39;</span><span class="p">)</span><span class="o">&#39;</span><span class="n">unknown</span><span class="w"> </span><span class="n">or</span><span class="w"> </span><span class="nb">missing</span><span class="w"> </span><span class="n">subcommand</span><span class="w"> </span><span class="p">[</span><span class="s">&#39;,trim(name),&#39;</span><span class="p">]</span><span class="o">&#39;</span><span class="w"></span>
<span class="w">    </span><span class="nb">write</span><span class="p">(</span><span class="o">*</span><span class="p">,</span><span class="s">&#39;(a)&#39;</span><span class="p">)[</span><span class="n">character</span><span class="p">(</span><span class="n">len</span><span class="p">=</span><span class="mi">80</span><span class="p">)</span><span class="w"> </span><span class="p">::</span><span class="w">  </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">    </span><span class="s">&#39; allowed subcommands are          &#39;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">    </span><span class="s">&#39;   * run  -l -L -title -x -y -z   &#39;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">    </span><span class="s">&#39;   * test -l -L -title            &#39;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="w"></span>
<span class="w">    </span><span class="s">&#39;&#39;</span><span class="w"> </span><span class="p">]</span><span class="w"></span>
<span class="w">    </span><span class="nb">stop</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"> </span><span class="n">select</span><span class="w"></span>
<span class="k">end</span><span class="w"> </span><span class="n">subroutine</span><span class="w"> </span><span class="n">parse</span><span class="w"></span>
<span class="k">end</span><span class="w"> </span><span class="n">program</span><span class="w"> </span><span class="n">demo_get_subcommand</span><span class="w"></span>
</code></pre></div>

<h2 id="author">AUTHOR</h2>
<div class="codehilite"><pre><span></span><code>  John S. Urban, 2019
</code></pre></div>

<h2 id="license">LICENSE</h2>
<div class="codehilite"><pre><span></span><code>  Public Domain
</code></pre></div>
    

    <h3>Arguments</h3>
    
    <em>None</em>
    <br>
    
    
    
    
    
    
    
   <h3>Return Value <small><span class="anchor" id="variable-sub"></span>character(len=:),
  allocatable</small></h3>
    
    
    
    
     
    <br>

    <section class="visible-xs visible-sm hidden-md">
      
<h3>Contents</h3>
 



<div class="panel panel-primary">
  <div class="panel-heading text-left"><h3 class="panel-title"><a data-toggle="collapse" href="#vars-1">Variables</a></h3></div>
  <div id="vars-1" class="panel-collapse collapse">
    <div class="list-group">
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-array">array</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-cmdarg">cmdarg</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-i">i</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-ilongest">ilongest</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-j">j</a>
      
      <a class="list-group-item" href="../proc/get_subcommand.html#variable-prototype">prototype</a>
      
    </div>
  </div>
</div>




















<div class="panel panel-primary">
  <div class="panel-heading text-left"><h3 class="panel-title">Source Code</h3></div>
  <div class="list-group">
    <a class="list-group-item" href="../proc/get_subcommand.html#src">get_subcommand</a>
  </div>
</div>



    </section>
    <br class="visible-xs visible-sm hidden-md">

    

    
    <section>    
      <h2>Variables</h2>
    
<table class="table table-striped varlist">
<thead><tr><th>Type</th><th>Visibility</th>

<th>Attributes</th><th></th><th>Name</th><th></th><th>Initial</th><th></th></thead>



<tbody>

  
  
  
  
<tr>
  
  <td><span class="anchor" id="variable-array"></span>character(len=:),</td>
  
  <td>public,</td>
  <td>allocatable</td><td>::</td>
  <td><strong>array</strong>(:)</td><td></td><td></td><td></td>
  
</tr>

  
  
  
  
<tr>
  
  <td><span class="anchor" id="variable-cmdarg"></span>character(len=:),</td>
  
  <td>public,</td>
  <td>allocatable</td><td>::</td>
  <td><strong>cmdarg</strong></td><td></td><td></td><td></td>
  
</tr>

  
  
  
  
<tr>
  
  <td><span class="anchor" id="variable-i"></span>integer,</td>
  
  <td>public</td>
  <td></td><td>::</td>
  <td><strong>i</strong></td><td></td><td></td><td></td>
  
</tr>

  
  
  
  
<tr>
  
  <td><span class="anchor" id="variable-ilongest"></span>integer,</td>
  
  <td>public</td>
  <td></td><td>::</td>
  <td><strong>ilongest</strong></td><td></td><td></td><td></td>
  
</tr>

  
  
  
  
<tr>
  
  <td><span class="anchor" id="variable-j"></span>integer,</td>
  
  <td>public</td>
  <td></td><td>::</td>
  <td><strong>j</strong></td><td></td><td></td><td></td>
  
</tr>

  
  
  
  
<tr>
  
  <td><span class="anchor" id="variable-prototype"></span>character(len=:),</td>
  
  <td>public,</td>
  <td>allocatable</td><td>::</td>
  <td><strong>prototype</strong></td><td></td><td></td><td></td>
  
</tr>

</tbody>
</table>

    </section>
    <br>
    
    
    
    
    

    
    
    
    
    


    
    
    
    <section>
    <h2><span class="anchor" id="src"></span>Source Code</h2>
    <div class="highlight"><pre><span></span><span class="k">function </span><span class="n">get_subcommand</span><span class="p">()</span> <span class="k">result</span><span class="p">(</span><span class="n">sub</span><span class="p">)</span>

<span class="c">! ident_3=&quot;@(#)M_CLI2::get_subcommand(3f): parse prototype string to get subcommand, allowing for response files&quot;</span>

<span class="kt">character</span><span class="p">(</span><span class="nb">len</span><span class="o">=</span><span class="p">:),</span><span class="k">allocatable</span>  <span class="kd">::</span> <span class="n">sub</span>
<span class="kt">character</span><span class="p">(</span><span class="nb">len</span><span class="o">=</span><span class="p">:),</span><span class="k">allocatable</span>  <span class="kd">::</span> <span class="n">cmdarg</span>
<span class="kt">character</span><span class="p">(</span><span class="nb">len</span><span class="o">=</span><span class="p">:),</span><span class="k">allocatable</span>  <span class="kd">::</span> <span class="k">array</span><span class="p">(:)</span>
<span class="kt">character</span><span class="p">(</span><span class="nb">len</span><span class="o">=</span><span class="p">:),</span><span class="k">allocatable</span>  <span class="kd">::</span> <span class="n">prototype</span>
<span class="kt">integer</span>                       <span class="kd">::</span> <span class="n">ilongest</span>
<span class="kt">integer</span>                       <span class="kd">::</span> <span class="n">i</span>
<span class="kt">integer</span>                       <span class="kd">::</span> <span class="n">j</span>
   <span class="n">G_subcommand</span><span class="o">=</span><span class="s1">&#39;&#39;</span>
   <span class="n">G_options_only</span><span class="o">=</span><span class="p">.</span><span class="n">true</span><span class="p">.</span>
   <span class="n">sub</span><span class="o">=</span><span class="s1">&#39;&#39;</span>

   <span class="k">if</span><span class="p">(.</span><span class="nb">not</span><span class="p">.</span><span class="nb">allocated</span><span class="p">(</span><span class="n">unnamed</span><span class="p">))</span><span class="k">then</span>
<span class="k">      allocate</span><span class="p">(</span><span class="kt">character</span><span class="p">(</span><span class="nb">len</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="kd">::</span> <span class="n">unnamed</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
   <span class="k">endif</span>

<span class="k">   </span><span class="n">ilongest</span><span class="o">=</span><span class="n">longest_command_argument</span><span class="p">()</span>
   <span class="k">allocate</span><span class="p">(</span><span class="kt">character</span><span class="p">(</span><span class="nb">len</span><span class="o">=</span><span class="nb">max</span><span class="p">(</span><span class="mi">63</span><span class="p">,</span><span class="n">ilongest</span><span class="p">))</span><span class="kd">::</span> <span class="n">cmdarg</span><span class="p">)</span>
   <span class="n">cmdarg</span><span class="p">(:)</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
   <span class="c">! look for @NAME if CLI_RESPONSE_FILE=.TRUE. AND LOAD THEM</span>
   <span class="k">do </span><span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">command_argument_count</span><span class="p">()</span>
      <span class="k">call </span><span class="nb">get_command_argument</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">cmdarg</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span><span class="nb">adjustl</span><span class="p">(</span><span class="n">cmdarg</span><span class="p">(</span><span class="mi">1</span><span class="p">:</span><span class="mi">1</span><span class="p">))</span> <span class="p">.</span><span class="n">eq</span><span class="p">.</span> <span class="s1">&#39;@&#39;</span><span class="p">)</span><span class="k">then</span>
<span class="k">         call </span><span class="n">get_prototype</span><span class="p">(</span><span class="n">cmdarg</span><span class="p">,</span><span class="n">prototype</span><span class="p">)</span>
         <span class="k">call </span><span class="n">split</span><span class="p">(</span><span class="n">prototype</span><span class="p">,</span><span class="k">array</span><span class="p">)</span>
         <span class="c">! assume that if using subcommands first word not starting with dash is the subcommand</span>
         <span class="k">do </span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span><span class="n">size</span><span class="p">(</span><span class="k">array</span><span class="p">)</span>
            <span class="k">if</span><span class="p">(</span><span class="nb">adjustl</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="n">j</span><span class="p">)(</span><span class="mi">1</span><span class="p">:</span><span class="mi">1</span><span class="p">))</span> <span class="p">.</span><span class="n">ne</span><span class="p">.</span> <span class="s1">&#39;-&#39;</span><span class="p">)</span><span class="k">then</span>
<span class="k">            </span><span class="n">G_subcommand</span><span class="o">=</span><span class="nb">trim</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="n">j</span><span class="p">))</span>
            <span class="n">sub</span><span class="o">=</span><span class="n">G_subcommand</span>
            <span class="k">exit</span>
<span class="k">         endif</span>
<span class="k">         enddo</span>
<span class="k">      endif</span>
<span class="k">   enddo</span>

<span class="k">   if</span><span class="p">(</span><span class="n">G_subcommand</span><span class="p">.</span><span class="n">ne</span><span class="p">.</span><span class="s1">&#39;&#39;</span><span class="p">)</span><span class="k">then</span>
<span class="k">      </span><span class="n">sub</span><span class="o">=</span><span class="n">G_subcommand</span>
   <span class="n">elseif</span><span class="p">(</span><span class="n">size</span><span class="p">(</span><span class="n">unnamed</span><span class="p">).</span><span class="n">ne</span><span class="p">.</span><span class="mi">0</span><span class="p">)</span><span class="k">then</span>
<span class="k">      </span><span class="n">sub</span><span class="o">=</span><span class="n">unnamed</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
   <span class="k">else</span>
<span class="k">      </span><span class="n">cmdarg</span><span class="p">(:)</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
      <span class="k">do </span><span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">command_argument_count</span><span class="p">()</span>
         <span class="k">call </span><span class="nb">get_command_argument</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">cmdarg</span><span class="p">)</span>
         <span class="k">if</span><span class="p">(</span><span class="nb">adjustl</span><span class="p">(</span><span class="n">cmdarg</span><span class="p">(</span><span class="mi">1</span><span class="p">:</span><span class="mi">1</span><span class="p">))</span> <span class="p">.</span><span class="n">ne</span><span class="p">.</span> <span class="s1">&#39;-&#39;</span><span class="p">)</span><span class="k">then</span>
<span class="k">            </span><span class="n">sub</span><span class="o">=</span><span class="nb">trim</span><span class="p">(</span><span class="n">cmdarg</span><span class="p">)</span>
           <span class="k">exit</span>
<span class="k">        endif</span>
<span class="k">      enddo</span>
<span class="k">   endif</span>
<span class="k">   </span><span class="n">G_options_only</span><span class="o">=</span><span class="p">.</span><span class="n">false</span><span class="p">.</span>
<span class="k">end function </span><span class="n">get_subcommand</span>
</pre></div>

    </section>
    <br>
    
    
    </div>
  </div>


    <hr>    
    </div> <!-- /container -->
    <footer>
      <div class="container">
      <div class="row">
        <div class="col-xs-6 col-md-4"><p>&copy; 2022 
                                          </p></div>
        <div class="col-xs-6 col-md-4 col-md-push-4">
          <p class="text-right">
            Documentation generated by 
            <a href="https://github.com/cmacmackin/ford">FORD</a>
             on 2022-06-08 21:13  
          </p>
        </div>
        <div class="col-xs-12 col-md-4 col-md-pull-4"><p class="text-center"> M_CLI2 was developed by John S. Urban</p></div>
      </div>
      <br>
      </div> <!-- /container -->    
    </footer>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
<!--
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
-->
    <script src="../js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../js/ie10-viewport-bug-workaround.js"></script>

    <!-- MathJax JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'AMS' } },
        jax: ['input/TeX','input/MathML','output/HTML-CSS'],
        extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']
      });
    </script>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    
    <script src="../tipuesearch/tipuesearch_content.js"></script>
    <script src="../tipuesearch/tipuesearch_set.js"></script>
    <script src="../tipuesearch/tipuesearch.js"></script>
    
    
  </body>
</html>